const express = require("express");

const app = express();

// app.use((req, res, next) => {
//   if (req.headers["content-type"] === "application/json") {
//     req.on("data", (data) => {
//       const info = JSON.parse(data.toString());
//       req.body = info;
//     });

//     req.on("end", () => {
//       next();
//     });
//   } else {
//     next();
//   }
// });

app.use(express.json());
app.use(express.urlencoded(({extended: true})));

app.post("/login", (req, res, next) => {
  console.log(req.body);
  res.end("登录");
});

app.use("/product", (req, res, next) => {
  console.log(req.body);
  res.end("更新");
});

app.listen(8000, () => {
  console.log("中间件的应用-json解析服务器启动成功~~~");
});
